﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FantasyBlog.DAL;

namespace FantasyBlog.BLL
{
    public class PostProvider:IPostProvider
    {
        public IQueryable<DAL.Post> GetPosts()
        {
            var posts = (from p in Model.PostSet
                         orderby p.date descending
                         select p);
            return posts;
        }

        public IQueryable<DAL.Post> GetTagPosts(string tag)
        {
            var term = (from t in Model.TermSet
                        where t.name == tag
                        select t).FirstOrDefault();
            var posts = (from p in term.Posts
                         orderby p.date descending
                         select p);
            return posts.AsQueryable();
        }

        public IQueryable<DAL.Post> GetPostByUser(string username)
        {
            var posts = (from p in Model.PostSet
                         where p.PostUser.username == username
                         select p);
            return posts;
        }

        public IQueryable<DAL.Post> GetPostByDate(DateTime starttime, DateTime endtime)
        {
            var posts = (from p in Model.PostSet
                         where p.date >= starttime && p.date <= endtime
                         select p);
            return posts;
        }

        public IQueryable<DAL.Post> SearhPost(string Keyword)
        {
            var posts = (from p in Model.PostSet
                         where p.title.Contains(Keyword)
                         select p);
            return posts;
        }


        private BlogModelContainer Model = new BlogModelContainer();
    }
}
